function ValidateBidPrice(bid_amount,mylastbid,maxbid,minincrease,proxy,initial_price)
{
   if (parseFloat(bid_amount.value)<=0 || isNaN(parseFloat(bid_amount.value))){
	   alert(language["bid_err_empty_bid"]);
	   return false;
   }
	if(parseFloat(maxbid.value)>0){
		accepted_price = parseFloat(maxbid.value) + parseFloat(minincrease.value);
		if(accepted_price>parseFloat(bid_amount.value)){
			alert(language["bid_err_increase"]+' ' + accepted_price + ' ' + auction_currency);
			return false;
		}
	}
	if(parseFloat(mylastbid.value)>0){
		accepted_price = parseFloat(mylastbid.value) + parseFloat(minincrease.value);
		if(accepted_price>parseFloat(bid_amount.value)){
			alert(language["bid_err_must_be_greater_mybid"]+' ' + accepted_price + ' ' + auction_currency);
			return false;
		}
	}
	if(parseFloat(initial_price.value)>0){
		accepted_price = parseFloat(initial_price.value);
		if(accepted_price>parseFloat(bid_amount.value)){
			alert(language["bid_err_must_be_greater"]+' ' + accepted_price + ' ' + auction_currency);
			return false;
		}
	}
	return true;
}
function FormValidate(form)
{
    if (form.name=='auctionRateForm')
    {
    	var rate = form.elements['rate'];

        if (isNaN(parseInt(rate.value))||parseInt(rate.value)<=0)
        {
    		alert(language["bid_must_rate"]);
    		return false;
        }
        return true;
    }
	var initial_price = form.elements['initial_price'];
	var bin = form.elements['bin_price'];
	var mylastbid =  form.elements['mylastbid'];
	var minincrease =  form.elements['min_increase'];
	var maxbid = form.elements['maxbid'];
	var proxy = form.elements['prxo'];
	var bid_amount= form.elements['amount'];

// verify if Terms and conditions are checked
	var terms = $('agreement'); //just one checkbox for all forms
	if( must_accept_term && !terms.checked){
		alert(language["bid_err_terms"]);
		return false;
	}
//the bid must be greater than mylastbid and greater then lastbid
	if(!ValidateBidPrice(bid_amount,mylastbid,maxbid,minincrease,proxy,initial_price)){
		return false;
	}
	if (parseFloat(bin.value)>0){
		if( parseFloat(bid_amount.value) >= parseFloat(bin.value)) {
			//greater then BIN - Warn
			var answer = confirm(language["bid_bid_greater_than_bin"]);
			if(answer == 0) return false;
		}
	}

	if ( buyers_premium > 0 ){
		alert(language['bid_premium_notice']);
	}

	return true;
}
function SelectTab()
{
    if (document.location.hash=='#messages' && tabPane1.pages.length>=3){
         tabPane1.setSelectedIndex(2);
    }
    if (document.location.hash=='#bid' && tabPane1.pages.length>=1){
         tabPane1.setSelectedIndex(0);
    }
    if (document.location.hash=='#bid_list' && tabPane1.pages.length>=1){
         tabPane1.setSelectedIndex(0);
    }
}
function MakeBinBid(form, bin_price, currency_name)
{

    nr_items=parseInt(document.getElementById("system_bin_quantity").value);
	if(has_quantity){
		var lang_confirm = language["bin_js_alert_q"];
		lang_confirm = lang_confirm.replace("NITEMS",nr_items);
		lang_confirm = lang_confirm.replace("VALUE", bin_price*nr_items + ' ' + currency_name );
	}else{
	   	var lang_confirm = language["bin_js_alert"];
		lang_confirm = lang_confirm.replace("VALUE", bin_price + ' ' + currency_name );
	}

    if (!confirm(lang_confirm)) return false;
    form.quantity.value=nr_items;
    return true;
}
function SendMessage(link,message_id,bidder_id,username)
{
    if (!bidder_id) bidder_id=0;
    if (!message_id) message_id=0;
    if (link) link.style.display='none';
    document.getElementById('bidder_id').value=bidder_id;
    document.getElementById('idmsg').value=message_id;
    if (tabPane1.pages.length>1){
         tabPane1.setSelectedIndex(tabPane1.pages.length-1);
    }
    document.getElementById('msg').style.display='block';
    document.getElementById('message_to').innerHTML=username;
    document.getElementById('message').focus();
}
function ProxyClick(checkbox)
{
    if(checkbox.checked) {
            document.getElementById('bid').innerHTML=language["bid_maxpp"];
            document.getElementById('prxo').value=1;
    } else{
         document.getElementById('prxo').value=0;
         document.getElementById('bid').innerHTML=language["bid_bid_price"];
    }
}
// Since 1.6.6
//
function suggestPrice(el){
    frm=el.form;
 	var d = frm.bid_suggest.value;
	if(d)
        frm.submit();
	else
		alert(language["bid_err_empty_suggest"]);
}

function suggestThisPrice(){

 	var d = document.getElementById('form_bid_suggest').value;
	if(d)
		document.form_suggestPrice.submit();
	else
		alert(language["bid_err_empty_suggest"]);
}

function refreshSuggestPrice(){

	total = document.getElementById('bid_suggest').value * document.getElementById('system_quantity').value;

	document.getElementById("bid_suggest_total").innerHTML=total;

}
function refreshSuggestList_Price(total, quantity, someId){

	total = total * quantity;
	document.getElementById(someId).innerHTML=total;

}
function removeFilters()
{
   document.auctionForm.task.value='removeFilters';
   document.auctionForm.submit();

}

function launchpca(amount,fromC,toC) {
    XECurrencyWindow = window.open ('', 'XECurrencyWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=200,width=620');
    XECurrencyWindow.focus();
    XECurrencyWindow.location.href = 'http://www.xe.com/pca/input.php?Amount='+amount+'&FromSelect='+fromC+'&ToSelect='+toC;
}